#ifndef									__BOOSTASYNCTCPSOCKET_H__
#	define								__BOOSTASYNCTCPSOCKET_H__

#	include								<boost/asio.hpp>
#	include								<boost/asio/deadline_timer.hpp>
#	include								"AAsyncTcpSocket.h"
#	include								"ServiceManager.h"

class									BoostAsyncTcpSocket : public AAsyncTcpSocket
{
public:
	BoostAsyncTcpSocket(Processor &, boost::asio::io_service &, unsigned short);
	virtual ~BoostAsyncTcpSocket();

public:
	virtual void						connectToHost(const std::string &, const std::string &);
	virtual void						init();
	virtual size_t						write(byte*, size_t);
	virtual	void						close();
	virtual void						sendOrder(IOrder*);
	virtual std::string					getIp();

private:
	Processor							&_proc;
	boost::asio::io_service				&_service;
	boost::asio::ip::tcp::socket		_socket;
	byte								_tmp_buf[4096];
	unsigned short						_current_msg;
	unsigned short						_id;
	boost::asio::deadline_timer			_heartbeat_timer;

private:
	void								OnConnect(const boost::system::error_code&, boost::asio::ip::tcp::resolver::iterator);
	void								startRead();
	void								handle_write(const boost::system::error_code&);
	void								OnReceive(const boost::system::error_code&, size_t);
	void								OnSend(const boost::system::error_code&);
	void								DoClose();
	void								start_heartbeat();
	void								handle_heartbeat(const boost::system::error_code&);

public:
	boost::asio::ip::tcp::socket		&getSocket();
	void								getOrderSize();
};

#endif									// !__BOOSTASYNCTCPSOCKET_H__
